<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    var isUnivalTree = function(root) {
    if (!root) {
        return true;
    }
    if (root.left) {
        if (root.val !== root.left.val || !isUnivalTree(root.left)) {
            return false;
        }
    }
    if (root.right) {
        if (root.val !== root.right.val || !isUnivalTree(root.right)) {
            return false;
        }
    }
    return true;
};
console.log(isUnivalTree([1,1,1,1,1,null]));
  </script>
</body>
</html>